-- Rattle App1

-- Setup Physic
local physics = require ("physics")
physics.start()
physics.setScale(60)
physics.setGravity(0,9.8)

-- Setup BackGround
display.setStatusBar(display.HiddenStatusBar)
background = display.newGroup()
foreground = display.newGroup()
	

-- Setup Sound Effects
local boingSound = audio.loadSound("boing_wav.wav")
local knockSound = audio.loadSound("knock_wav.wav")
local squishSound = audio.loadSound("squish_wav.wav")

local function OnBigBounce (self, event)
	audio.play(boingSound)
end

local function OnMidBounce (self, event)
	audio.play(knockSound)
end

local function OnSmallBounce (self, event)
	audio.play(squishSound)
end


	
local BG = display.newImage("BG.png")
background:insert(BG,true)
BG.x = 480
BG.y = 320

local borderTop = display.newRect(0,0,960,0)
borderTop:setFillColor(0,0,0,0)
physics.addBody (borderTop, "static", borderBodyElement)
borderTop.collision = OnBigBounce
borderTop:addEventListener ("collision", borderTop)

local borderBut = display.newRect(0, 640, 960, 0)
borderBut:setFillColor(0,0,0,0)
physics.addBody (borderBut , "static", borderBodyElement)
borderBut.collision = OnBigBounce
borderBut:addEventListener ("collision", borderBut)

local borderLeft = display.newRect(0, 0, 0, 640)
borderLeft:setFillColor(0,0,0,0)
physics.addBody(borderLeft, "static", borderBodyElement)
borderLeft.collision = OnBigBounce
borderLeft:addEventListener ("collision", borderLeft)

local borderRight = display.newRect( 960, 0, 0, 640 )
borderRight:setFillColor (0,0,0,0)
physics.addBody(borderRight, "static", borderBodyElement)
borderRight.collision = OnBigBounce
borderRight:addEventListener ("collision", borderRight)


local physicsData = (require "circlepe").physicsData(1.0)


function popCircle()
	IMG_Container = "Container_Circle";
	obj_Container = display.newImage(IMG_Container..".png");
	background:insert(obj_Container)
	obj_Container.x = 480
	obj_Container.y = 320;
	physics.addBody(obj_Container, physicsData:get(IMG_Container));	
	
	IMG_Circle1 = "Circle1";
	obj_Circle1 = display.newImage(IMG_Circle1..".png");
	background:insert(obj_Circle1)
	obj_Circle1.x = 480
	obj_Circle1.y = 320;
	physics.addBody(obj_Circle1, physicsData:get(IMG_Circle1));	
	obj_Circle1.collision = OnMidBounce
	obj_Circle1:addEventListener ("collision", obj_Circle1)
	
	
	IMG_Circle2 = "Circle2";
	obj_Circle2 = display.newImage(IMG_Circle2..".png");
	background:insert(obj_Circle2)
	obj_Circle2.x = 400
	obj_Circle2.y = 320;
	physics.addBody(obj_Circle2, physicsData:get(IMG_Circle2));	
	obj_Circle2.collision = OnSmallBounce
	obj_Circle2:addEventListener ("collision", obj_Circle2)
	
	IMG_Circle3 = "Circle3";
	obj_Circle3 = display.newImage(IMG_Circle3..".png");
	background:insert(obj_Circle3)
	obj_Circle3.x = 400
	obj_Circle3.y = 320;
	physics.addBody(obj_Circle3, physicsData:get(IMG_Circle3));	
	obj_Circle3.collision = OnSmallBounce
	obj_Circle3:addEventListener ("collision", obj_Circle3)
	
	
end


popCircle()